﻿import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { SatelliteQuery, SatellitePageResult, SatelliteForm } from "./types";

/**
 * 获取卫星设备分页数据
 *
 * @param queryParams
 */
export function getSatellitePage(
  queryParams?: SatelliteQuery
): AxiosPromise<SatellitePageResult> {
  return request({
    url: '/api/v1/device/gpsMac/page',
    method: 'get',
    params: queryParams
  });
}

export function reRestartToServer(mac: string): AxiosPromise<Boolean> {
	return request({
		url: '/api/v1/device/gpsMac/reRestart?mac=' + mac ,
		method: 'get'
	});
}


/**
 * 获取卫星设备下拉数据
 *
 * @param queryParams
 */
export function listSatelliteOptions(
  queryParams?: SatelliteQuery
): AxiosPromise<OptionType[]> {
  return request({
    url: '/api/v1/device/options',
    method: 'get',
    params: queryParams
  });
}

/**
 * 获取卫星设备的菜单ID集合
 *
 * @param queryParams
 */
export function getSatelliteMenuIds(roleId: number): AxiosPromise<number[]> {
  return request({
    url: '/api/v1/device/' + roleId + '/menuIds',
    method: 'get'
  });
}

/**
 * 获取卫星设备详情
 *
 * @param id
 */
export function getSatelliteForm(id: number): AxiosPromise<SatelliteForm> {
  return request({
    url: '/api/v1/device/' + id + '/form',
    method: 'get'
  });
}

export function getSatelliteConfigForm(id: number): AxiosPromise<SatelliteForm> {
	return request({
		url: '/api/v1/device/config/' + id ,
		method: 'get'
	});
}

/**
 * 添加卫星设备
 *
 * @param data
 */
export function addOrUpdate(data: SatelliteForm) {
  return request({
    url: '/api/v1/device/gpsMac/addOrUpdate',
    method: 'post',
    data: data
  });
}

/**
 * 更新卫星设备
 *
 * @param id
 * @param data
 */
export function updateSatellite(id: number, data: SatelliteForm) {
  return request({
    url: '/api/v1/device/update/' + id,
    method: 'post',
    data: data
  });
}
export function updateSatelliteConfig(deviceId: number, data: SatelliteConfigForm) {
	return request({
		url: '/api/v1/device/updateConfig/' + deviceId,
		method: 'post',
		data: data
	});
}

/**
 * 批量删除卫星设备，多个以英文逗号(,)分割
 *
 * @param ids
 */
export function deleteSatellites(ids: string) {
  return request({
    url: '/api/v1/device/' + ids,
    method: 'delete'
  });
}
